package com.wande.dataplatform.etl.node;

import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 * ETL节点执行结果
 *
 * @author dataplatform
 */
@Data
public class EtlNodeResult {

    /**
     * 是否成功
     */
    private boolean success;

    /**
     * 错误信息
     */
    private String errorMessage;

    /**
     * 处理的数据
     */
    private List<Map<String, Object>> data;

    /**
     * 处理行数
     */
    private long processedRows;

    /**
     * 成功行数
     */
    private long successRows;

    /**
     * 失败行数
     */
    private long failedRows;

    public static EtlNodeResult success(List<Map<String, Object>> data) {
        EtlNodeResult result = new EtlNodeResult();
        result.setSuccess(true);
        result.setData(data);
        result.setProcessedRows(data != null ? data.size() : 0);
        result.setSuccessRows(data != null ? data.size() : 0);
        result.setFailedRows(0);
        return result;
    }

    public static EtlNodeResult failure(String errorMessage) {
        EtlNodeResult result = new EtlNodeResult();
        result.setSuccess(false);
        result.setErrorMessage(errorMessage);
        result.setProcessedRows(0);
        result.setSuccessRows(0);
        result.setFailedRows(0);
        return result;
    }
}
